package com.pactera.miyuangroup.controller.app;

import com.pactera.miyuangroup.service.ReplenishmentService;
import com.pactera.miyuangroup.vo.request.VoidRequest;
import com.pactera.miyuangroup.vo.request.app.AppAddReplenishmentReq;
import com.pactera.miyuangroup.vo.response.ResultModel;
import com.pactera.miyuangroup.vo.response.app.AppAddReplenishmentRes;
import com.pactera.miyuangroup.vo.response.app.AppReplenishmentRes;
import com.pactera.miyuangroup.vo.response.web.ReplenishmentRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述:
 *  补货完成
 * @outhor 张汉卿
 * @create 2018-04-28 14:44
 */


@Api(description = "补货记录接口")
@RestController
@RequestMapping("/app/replenishment")
@Slf4j
public class AppReplenishmentController {

    @Autowired
    private ReplenishmentService replenishmentService;

    @ApiOperation(value = "工控号查询补货机信息", notes = "工控号查询补货机信息")
    @ApiImplicitParams({@ApiImplicitParam(value = "售货机ID", name = "controlNumber", required = true, paramType = "path")})
    @RequestMapping(value = "/{controlNumber}/getVendorInfo", method = RequestMethod.POST)
    private ResultModel<AppReplenishmentRes> getVendorInfo(@PathVariable String controlNumber){

        AppReplenishmentRes appReplenishmentRes = replenishmentService.getAppVendorInfo(controlNumber);

        return ResultModel.ok(appReplenishmentRes);
    }


    @ApiOperation(value = "完成补货", notes = "完成补货")
    @RequestMapping(value = "/addReplenishment", method = RequestMethod.POST)
    private ResultModel<AppAddReplenishmentRes> addReplenishment(@RequestBody AppAddReplenishmentReq appAddReplenishmentReq){

        log.info("插入补货记录");
        boolean isInsert = replenishmentService.addReplenishmentRes(appAddReplenishmentReq);

        if(isInsert){
            return ResultModel.ok();
        }
        return ResultModel.fail();

    }

}
